import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import { BaseHttpService } from '../shared/services/baseHttp.service';

@Injectable()
export class CompanyRiskService extends BaseHttpService {
    public company: Promise<any>;
    public mei: Promise<any>;

    constructor(private http: Http) {
        super(http);
    }

    public getCompanyById(companyId: string): Promise<any> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId);
    }    
    
    public getCompanyUniverseBenchmark(companyId: string): Promise<any> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/benchmark/universe');
    }

    public getCompanySubIndustryBenchmark(companyId: string): Promise<any> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/benchmark/subindustry');
    }

    public getCompanyMeiSubIndustryBenchmark(companyId: string, externalId: number): Promise<any> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/benchmark/mei/' + externalId);
    }

    public getCompanySubIndustryExposure(companyId: string): Promise<any[]> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/benchmark/exposure');
    }

    public getCompanyMeiSubIndustryExposure(companyId: string, externalId: number): Promise<any[]> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/benchmark/mei/' + externalId + '/exposure');
    }

    public addToPortfolio(companyId: string, companyName: string, tickerExchange: string): void {
        this.gaService.addToPortfolio(companyId, companyName, tickerExchange);
    }

    public downloadReport(companyId: string, companyUrlFriendlyName: string, summary: boolean): void {
        this.gaService.downloadReport(companyId, companyUrlFriendlyName, summary);
    }

    public getMeiById(companyId: string, externalId: string): Promise<any> {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/mei/' + externalId);
    }

    public getIndicatorByCode(companyId: string, externalId: string, code: string) : Promise<any> { 
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/mei/' + externalId + '/indicator/' + code);
    }

    public getEventsByCode(companyId:string, code:string):Promise<any>{
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/event/' + code);
    }

    public getLocationByEventCode(companyId:string,code:string):Promise<any[]>
    {
        return super.get<any[]>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/event/' + code+'/locations');
    }

    public getPillarDetails(companyId: string, number: string): Promise<any>
    {
        return super.get<any>(this.serverUrl + '/riskratingserv/api/v1/company/' + companyId + '/pillar/' + number);
    }
}